package com.cyy.common;

public class ResData<T> {
    public static final String SUCCESS = "0";
    public static final String FAIL = "100";   // 通用错误码

    private String code;

    private String msg;

    private T data;

    public static <T> ResData<T> success(){
        return success(null);
    }

    public static ResData success(Object data){
        ResData result = new ResData<>();
        result.setCode(SUCCESS);
        result.setMsg("ok");
        result.setData(data);
        return result;
    }


    public static ResData error(String msg){
        ResData result = new ResData<>();
        result.setCode(FAIL);
        result.setMsg(msg);
        return result;
    }

    public static ResData error(String code,String msg){
        ResData result = new ResData<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
